TreeGrid Master / Detail Tutorial
2. Master detail nested tables
Master detail relation in plain tables shown as children of master rows
-
Plain master detail relation is used to show the same data in the expandable children in different layout.
Master grid shows the data in rows and detail grid shows the one master row data in different structure, often vertically in column.
-
The data are defined only in master grid, only master grid stores the changes and can upload them back to server.
Detail grid defines only layout, the columns and fixed (summary) rows.
-
The master data structure is usually defined in three levels tree:
-
1. level Data row. The first level are the data rows displaying the data horizontally. They are the only defined rows, the other two levels are automatically created by grid according to the settings in row defaults.
The Data row default row (<D>) should define the one child (Master row) with its Def set. And it should define also CopyTo attribute to copy the cells from Data row to Master row after their change.
-
2. level Master row. The second level row is automatically created one child of the data row, usually fully spanned to show the detail grid in one (spanned) its cell.
This row is shown, when the Data row is expanded.
The Master row default (<D>) row should define all the detail children, with appropriate cell values and other attributes and also with CopyTo attributes to copy the values from the Detail row cells to the Master row.
The Master row default (<D>) row should also define appropriate CopyTo attributes to copy the cell values from Master row to Data row and also to Detail row.
It should have set also Expanded='0' CanExpand='0' to never show the detail rows in master grid.
-
3. level Detail row. The third level rows are automatically created children of the master row. defined in the Master row default row.
-
Oposite to external detail grids you don't need to define the detail columns in master grid.
If you use debug='check' to check errors in your XML, you will receive warnings for unknown attributes for these columns in detail rows. In this case you can ignore these warnings. Or list them in DebugCheckIgnore.
-
You can set attributes Sync and SyncId and optionally CfgId to synchronize all the detail grids.
For example if a user changes size of column in one detail grid, all other detail grids will be resized accordingly. Similarly for sorting, filtering, grouping and search settings.
-
The <D> cell attributes
CopyTo
will define which master cells will be copied to which detail row(s) and cells.
Usual value of the master CopyTo attribute is "Child_X,Y", where X is child row position from 0 and Y is column name.
For example NAMECopyTo='Child_2,VALUE' means that master row's NAME cell will be copied to the third child row, to the cell name VALUE.
-
The child row cell attributes
CopyTo
will define which detail cells will be copied to which master cells.
Usual value of the child CopyTo attribute is "Parent,Y", where Y is the master cell name.
For example VALUECopyTo='Parent,NAME' means that child row's VALUE cell will be copied to the master row's cell NAME.
-
How it works
-
On master grid load there will be created hidden children for every row according to the <D> definition.
To these children attributes will be copied values from the root rows, according to the <D> CopyTo attributes.
-
When some row in master grid is expanded to show the detail grid in children, all the master row's children are copied from master grid to detail grid and here are shown.
In this time are all the child rows at two placed (in master grid and in detail grid) and all changes are synchronized and mirrored to both.
-
When a user changes some value in master grid, in root row, the change is automatically copied to its hidden children and also mirrored to detail grid.
It is done by CopyTo attribute in <D> tag, similarly to the grid loading.
-
When a user changes some value in detail grid, the change is mirrored to hidden child in master grid and also copied to the parent row.
It is done by CopyTo attribute in <D> child <I> tag.
-
API
On showing the master row in detail grid is called API event OnShowDetail.
After the row is shown is called OnShowDetailFinish.
To manually show some master row in detail grid call API method ShowDetail.
To refresh or clear detail grid call RefreshDetail.